﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.Windows.Input;

namespace DynamicUIFramework
{
    [Export(typeof(CommandController))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class CommandController
    {
        Dictionary<string, ICommand> commands = new Dictionary<string, ICommand>();
        public Dictionary<string, ICommand> Commands
        {
            get { return commands; }
        }

        public ICommand GetCommand(string name)
        {
            if (commands.ContainsKey(name))
                return commands[name];
            return null;
        }

        public string GetCommandName(ICommand comm)
        {
            if (comm == null)
                return string.Empty;

            var res = Commands.FirstOrDefault(item => item.Value == comm);
            return res.Key == null ? string.Empty : res.Key;
        }
    }
}
